/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#include <sxViewportController.h>

const Sx::Graphics::Color4f DEFAULT_TEXT_COLOR = Sx::Graphics::Color4f(1.0f, 1.0f, 1.0f, 1.0f);
const Sx::Graphics::Color4f DEFAULT_BORDER_COLOR = Sx::Graphics::Color4f(0.4f);
const Sx::Graphics::Color4f DEFAULT_BORDER_SELECTED_COLOR = Sx::Graphics::Color4f(0.537255f, 0.705882f, 0.87451f, 1.0f);
const Sx::String DEFAULT_TEXT = "No Text";
const unsigned int DEFAULT_BORDER_WIDTH = 2;
const bool DEFAULT_DISPLAY_UI = true;
const bool DEFAULT_DISPLAY_TEXT = true;

Sx::Interface::ViewportController::ViewportController(Viewport* viewport) : Controller(viewport) {
	this->textColor = DEFAULT_TEXT_COLOR;
	this->borderColor = DEFAULT_BORDER_COLOR;
	this->borderColorSelected = DEFAULT_BORDER_SELECTED_COLOR;
	this->text = DEFAULT_TEXT;
	this->displayUI = true;
	this->selected = false;
	this->inEdit = false;
	this->borderWidth = DEFAULT_BORDER_WIDTH;
	this->displayUI = DEFAULT_DISPLAY_UI;
	this->displayText = DEFAULT_DISPLAY_TEXT;
	this->frameIndex = 0;
	this->initialized = false;
}

Sx::Interface::ViewportController::~ViewportController() {}

bool Sx::Interface::ViewportController::initialize() {
	this->initialized = true;
	return true;
}

bool Sx::Interface::ViewportController::preRender() const { return true; }
bool Sx::Interface::ViewportController::postRender() const { return true; }

void Sx::Interface::ViewportController::setClearColor(float r, float g, float b) {
	this->clearColor = Graphics::Color4f(r, g, b,  1.0f);
}

void Sx::Interface::ViewportController::setClearColor(float r, float g, float b, float a) {
	this->clearColor = Graphics::Color4f(r, g, b, a);
}

void Sx::Interface::ViewportController::setClearColor(const Graphics::Color3f& color) {
	this->clearColor = Graphics::Color4f(color.getR(), color.getG(), color.getB(), 1.0f);
}

void Sx::Interface::ViewportController::setClearColor(const Graphics::Color4f& color) {
	this->clearColor = color;
}

void Sx::Interface::ViewportController::setTextColor(float r, float g, float b) {
	this->textColor = Graphics::Color4f(r, g, b, 1.0f);
}

void Sx::Interface::ViewportController::setTextColor(float r, float g, float b, float a) {
	this->textColor = Graphics::Color4f(r, g, b, a);
}

void Sx::Interface::ViewportController::setTextColor(const Graphics::Color3f& color) {
	this->textColor = Graphics::Color4f(color.getR(), color.getG(), color.getB(), 1.0f);
}

void Sx::Interface::ViewportController::setTextColor(const Graphics::Color4f& color) {
	this->textColor = color;
}

void Sx::Interface::ViewportController::setBorderColor(float r, float g, float b, bool selected) {
	if ( selected == false ) this->borderColor = Graphics::Color4f(r, g, b, 1.0f);
	else this->borderColorSelected = Graphics::Color4f(r, g, b, 1.0f);
}

void Sx::Interface::ViewportController::setBorderColor(float r, float g, float b, float a, bool selected) {
	if ( selected == false ) this->borderColor = Graphics::Color4f(r, g, b, a);
	else this->borderColorSelected = Graphics::Color4f(r, g, b, a);
}

void Sx::Interface::ViewportController::setBorderColor(const Graphics::Color3f& color, bool selected) {
	if ( selected == false ) this->borderColor = Graphics::Color4f(color.getR(), color.getG(), color.getB(), 1.0f);
	else this->borderColorSelected = Graphics::Color4f(color.getR(), color.getG(), color.getB(), 1.0f);
}

void Sx::Interface::ViewportController::setBorderColor(const Graphics::Color4f& color, bool selected) {
	if ( selected == false ) this->borderColor = color;
	else this->borderColorSelected = color;
}

void Sx::Interface::ViewportController::setText(const String& text) {
	this->text = text;
}

void Sx::Interface::ViewportController::setPaused(bool paused) {
	this->paused = paused;
}

void Sx::Interface::ViewportController::pause() {
	this->paused = true;
}

void Sx::Interface::ViewportController::resume() {
	this->paused = false;
}

void Sx::Interface::ViewportController::setInputEnabled(bool enabled) {
	this->inputEnabled = enabled;
}

void Sx::Interface::ViewportController::enableInput() {
	this->inputEnabled = true;
}

void Sx::Interface::ViewportController::disableInput() {
	this->inputEnabled = false;
}

void Sx::Interface::ViewportController::setSelected(bool selected) {
	this->selected = selected;
}

void Sx::Interface::ViewportController::select() {
	this->selected = true;
}

void Sx::Interface::ViewportController::deselect() {
	this->selected = false;
}

void Sx::Interface::ViewportController::setBorderWidth(unsigned int width) {
	this->borderWidth = width;
}

Sx::String Sx::Interface::ViewportController::getText() const {
	return this->text;
}

Sx::Graphics::Color4f Sx::Interface::ViewportController::getClearColor() const {
	return this->clearColor;
}

Sx::Graphics::Color4f Sx::Interface::ViewportController::getTextColor() const {
	return this->textColor;
}

Sx::Graphics::Color4f Sx::Interface::ViewportController::getBorderColor(bool selected) {
	if ( selected == false ) return this->borderColor;
	else return this->borderColorSelected;
}

bool Sx::Interface::ViewportController::isSelected() const {
	return this->selected;
}

bool Sx::Interface::ViewportController::isInitialized() const {
	return this->initialized;
}

bool Sx::Interface::ViewportController::isPaused() const {
	return this->paused;
}

bool Sx::Interface::ViewportController::isInputEnabled() const {
	return this->inputEnabled;
}

bool Sx::Interface::ViewportController::isInEdit() const {
	return this->inEdit;
}

void Sx::Interface::ViewportController::incrementFrameIndex() {
	this->frameIndex++;
}

void Sx::Interface::ViewportController::setFrameIndex(unsigned int index) {
	this->frameIndex = index;
}

void Sx::Interface::ViewportController::resetFrameIndex() {
	this->frameIndex = 0;
}

void Sx::Interface::ViewportController::clearFrameIndex() {
	this->frameIndex = 0;
}

void Sx::Interface::ViewportController::setMouseCurrentPosition(int x, int y) {
	this->mousePosCur.x() = x;
	this->mousePosCur.y() = y;
}

void Sx::Interface::ViewportController::setMousePressPosition(int x, int y) {
	this->mousePosPress.x() = x;
	this->mousePosPress.y() = y;
}

void Sx::Interface::ViewportController::setMouseReleasePosition(int x, int y) {
	this->mousePosRelease.x() = x;
	this->mousePosRelease.y() = y;
}

void Sx::Interface::ViewportController::setMousePositionDifference(int x, int y) {
	this->positionDifference.x() = x;
	this->positionDifference.y() = y;
}

void Sx::Interface::ViewportController::setMousePositionDifference(const Eigen::Vector2i& positionDisplacement) {
	this->positionDifference = positionDisplacement;
}

void Sx::Interface::ViewportController::updateMouseLastPosition() {
	this->mousePosLast.x() = this->mousePosCur.x();
	this->mousePosLast.y() = this->mousePosCur.y();
}

void Sx::Interface::ViewportController::updateMousePositionDifference() {
	this->positionDifference.x() = this->mousePosLast.x() - this->mousePosCur.x();
	this->positionDifference.y() = this->mousePosLast.y() - this->mousePosCur.y();
}
